$(document).ready(function () {
    var schArea      = addressUri.getParam('schArea');
    var schCity      = addressUri.getParam('schCity');
    var key          = unescape(addressUri.getParam('key'));
    $('#search tr').each(function (i) {
        if(i==0 || i==2){
            $(this).remove();
        }
    });

    $('[name=area]').on("change", function (e) {
        var pid =  $('[name=area]').val();
        bindCity(pid);
    });

    if(schArea!=undefined && schCity!=undefined){
        $('[name=area]').val(schArea);
        bindCity(schArea);
        setTimeout(function () {
            $('[name=city]').val(schCity);
        },100);
    }

    if(key!=''){
        $('[name=key]').val(key);
    }
    $('#bt_modal_confirm',parent.document).click(function () {
        window.top.xhTop.getActiveFrame().schArea  = $('[name=area]').val();
        window.top.xhTop.getActiveFrame().schCity  = $('[name=city]').val();
        window.top.xhTop.getActiveFrame().strDom.textbox('setValue',$('[name=key]').val());
        window.top.xhTop.getActiveFrame().searchSch.click();
        window.top.xhTop.closeModal();
    });

});

function bindCity(pid) {
    var domCity = $('[name=city]');
    $.ajax({
        url:baseUrl+'tch/getDeps/'+pid,
        type:'post',
        dataType:'json',
        success:function (data) {
            domCity.empty();
            var str = '';
            str += '<option  value=""  selected>请选择市</option>';
            $.each(data,function (id,text) {
                str += '<option value="'+id+'" >'+text+'</option>';
            })

            domCity.append(str);
        },
        error:function (data) {
            console.log(data);
        }
    })
}